<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$site_name} 找回密码</title>
    <meta name="applicable-device" content="pc,mobile">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <script src="/static/js/layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/js/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/login.css" />
    <script src="/static/js/center.js?v={:release()}"></script>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
</head>
<body>
<div class="layui-fluid">
    <form class="layui-form layui-form-fixed" action="/index/user/forgot" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span> {:__('手机/邮箱')}</label>
            <div class="layui-input-inline" style="width: 306px">
                <input id="name" name="name" placeholder="{:__('请输入邮箱或手机号')}" type="text" class="layui-input"
                       lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span> {:__('验证码')}</label>
            <div class="layui-input-inline" style="width: 226px">
                <input name="captcha" placeholder="{:__('请输入验证码')}" type="text" class="layui-input"
                       autocomplete="off" lay-verify="required" maxlength="10"/>
            </div>
            <button id="uCode" class="layui-btn layui-btn-normal" type="button">{:__('获取')}
            </button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span> {:__('新密码')}</label>
            <div class="layui-input-inline" style="width: 306px">
                <input type="password" id="pwd" name="pwd" lay-verify="required" placeholder="{:__('密码')}"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center">
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">{:__('取消')}</button>
            <button class="layui-btn layui-btn-normal" lay-filter="submitIframe" lay-submit>{:__('提交')}</button>
        </div>
    </form>
</div>
</body>
<script>
    layui.use('jquery', function () {

        let $ = layui.jquery;
        $('#uCode').click(function (e) {
            let name = $('#name').val();
            if (name === '') {
                layer.msg('请输入邮箱或手机号', {icon: 5});
                return false;
            }
            let regUrl = '/api/ajax/smsSend';
            let data = { mobile: name };
            let regxEmail = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
            if (regxEmail.test(name)) {
                regUrl = '/api/ajax/emailSend';
                data = { email: name };
            }
            data.event = 'forgot';
            $(this).attr('disabled', true);
            $.ajax({
                url: regUrl,
                type: 'post',
                data: data,
                dataType: 'json',
                success: function (res) {

                    if (res.code === 200) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
            setTimeout(function () {
                $('#uCode').attr('disabled', false);
            }, 10000);
        });
    })
</script>
</html>